#####################################################################
# Product:      KnowledgeEngine (Plone Edition)
#
# File:         TypeInfo.py
#
# Copyright:    Copyright (c) 2006, Faulkner Technologies
#
# Author:       James Davies
#
# Description:  StubTypeInfo is used to pacify plone 2.5 so it accepts
#               KE's own action system.
#               
#####################################################################

from AccessControl import ClassSecurityInfo
from Globals import InitializeClass

class StubTypeInfo:
    """
        A Fake Plone "Type Info" class used to pacify Plone 2.5
    """
    
    security = ClassSecurityInfo()
    security.setDefaultAccess('allow')
    
    def __init__(self, object):
        """ Create the TypeInfo object, wrapping the specifed KE object """
        
        self.object    = object
        self.classinfo = object.getClassInfo()
    
    def Title(self):
        """ Returns the class title """
        return self.classinfo.getDisplayName()
    
    
    def Description(self):
        """ Returns the class description """
        return self.object.__doc__ # Return the class DocString
    
    def Metatype(self):
        """ Returns the class Meta Type """
        return self.classinfo.getClassName()
    
    def getIcon(self):
        """ Returns the class icon """
        return self.classinfo.getClassIcon()
    
    def allowType(self, contentType):
        """ Wrapper for isChildPermitted/isPermittedInContainer logic """
        if self.isChildPermitted( contentType ):
            if hasattr(contentType, 'getClassInfo'):
                return contentType.getClassInfo().isPermittedInContainer( self.classinfo, contentType, self.object )
            else:
                return True
            
    def getId(self):
        """ This Objects Id """
        return self.classinfo.getClassName()
    
    def allowDiscussion(self):
        
        return False
    
    def globalAllow(self):
        
        return False
    
    def listActions(self):
        """ No actions (KE Provides it's own action system) """
        return []
    
    def getActionInfo(self, *args, **kwargs):
        """ Provide a dummy url for any given 'action'. KE Renders it's own tabs, so this gets ignored """
        return {'url': 'foo'}
    
    def queryMethodID(self, alias, default=None, context=None):
        """ """
        
        return None
    
    
    def getActionById(self, *args, **kwargs):
        """ """
        
        return None
    
    
    
InitializeClass(StubTypeInfo)